import {myFetch, getParameterByName} from '@/assets/js/utils.js'
const env = process.env.NODE_ENV
let userId, userInfo

async function ifWxPayLoggedIn () {
    const {data, success} = await myFetch({
        name: 'shopping.sys.openidExist'
    })
    if (success) return
    else {
        const code = getParameterByName('code')
        if (code) await WxPayLogin(code)
        else {
            location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?
		appid=wxca54e54a9155264a&redirect_uri=${location.href}
		&response_type=code&scope=snsapi_base#wechat_redirect`
        }
    }
}

async function WxPayLogin (code) {
    const {data, success} = await myFetch({
        name: 'shopping.sys.pay.getopenid',
        code
    })
}

export default{
    async ifWxPayLoggedIn () {
        await ifWxPayLoggedIn()
    },
    async WxPayLogin (code) {
        await WxPayLogin()
    }
}
